<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>核对账单 - TMS</title>
    <link rel="stylesheet" href="/view/frame/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/view/frame/static/css/global.css?v=1.0">
    <link rel="stylesheet" href="/view/tms/static/css/add.css?v=1.0">
    <style>
      body {margin:20px;}
      span.required {color:#f00; font-family:'simsun', '宋体'; margin-right:5px; font-size:15px;}
      .layui-form-label {width:190px;}
      span{line-height: 38px; height: 38px}
      .layui-form-item .layui-input-inline {padding-top: 10px; width:270px;}
      a {color:#51a2f7 !important;}
      .pointer{color:#51a2f7; cursor:pointer ; overflow: hidden;white-space:nowrap;text-overflow:ellipsis;}
    </style>
  </head>
  <body>
    <form class="layui-form" autocomplete="off">
      <div class="layui-row">
          <div class="layui-col-sm4">
            <div class="layui-form-item">
                <label class="layui-form-label">账单号</label>
                <div class="layui-input-block">
                    <span id="receivedBillsNo" name="receivedBillsNo"></span>
                </div>
            </div>
          </div>
          <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">结算单位</label>
                    <div class="layui-input-block">
                        <span id="customerName" name="customerName"></span>
                    </div>
                </div>
          </div>
          <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">月份</label>
                    <div class="layui-input-block">
                        <span id="billMonth" name="billMonth"></span>
                    </div>
                </div>
          </div>
      </div>
      <div class="layui-row">
          <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">运输单量</label>
                    <div class="layui-input-block">
                        <span id="orderCount" name="orderCount"></span>
                    </div>
                </div>
          </div>
          <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">运输柜量</label>
                    <div class="layui-input-block">
                        <span id="arkCount" name="arkCount"></span>
                    </div>
                </div>
          </div>
          <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">应收运费(元)</label>
                    <div class="layui-input-block">
                        <span id="transportCost" name="transportCost"></span>
                    </div>
                </div>
          </div>
      </div>
      <div class="layui-row">
          <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">应收异常费(元)</label>
                    <div class="layui-input-block">
                        <span id="extraCost" name="extraCost"></span>
                    </div>
                </div>
          </div>
          <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label">应收合计(元)</label>
                    <div class="layui-input-block">
                        <span id="totalCost" name="totalCost"></span>
                    </div>
                </div>
          </div>
          <div class="layui-col-sm4">
                <div class="layui-form-item">
                     <label class="layui-form-label">上次提交实应收(元)</label>
                     <div class="layui-input-block">
                         <span id="receiveCost" name="receiveCost"></span>
                     </div>
                 </div>
           </div>
      </div>
      <div class="layui-row">
          <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">差异运单运费</label>
                        <div class="layui-input-block">
                            <span id="badWayTransportCost" name="badWayTransportCost"></span>
                        </div>
                    </div>
          </div>
          <div class="layui-col-sm4">
               <div class="layui-form-item">
                    <label class="layui-form-label">差异运单异常费</label>
                    <div class="layui-input-block">
                        <span id="badWayExtraCost" name="badWayExtraCost"></span>
                    </div>
                </div>
          </div>
          <div class="layui-col-sm4">
               <div class="layui-form-item">
                    <label class="layui-form-label">差异运单费用合计</label>
                    <div class="layui-input-block">
                        <span id="badWaySum" name="badWaySum"></span>
                    </div>
                </div>
          </div>
      </div>
      <div class="layui-row">
            <div class="layui-col-sm12">
                  <div class="layui-form-item"> 
                      <label class="layui-form-label">差异运单号</label>
                      <div class="layui-input-block">
                          <div class="pointer">
                              <span id="badJobsNo" name="badJobsNo"></span>
                          </div>
                      </div>
                  </div>
              </div>
        </div>
      <div class="layui-row">
          <div class="layui-col-sm4"> 
              <div class="layui-form-item">
                    <label class="layui-form-label">对方提交应付金额(元)</label>
                    <div class="layui-input-block">
                        <span id="handleCost" name="handleCost"></span>
                    </div>
                </div>
          </div>
          <div class="layui-col-sm4"> 
              <div class="layui-form-item">
                <label class="layui-form-label">对方是否同意上份账单</label>
                <div class="layui-input-block">
                    <span id="isAgree" name="isAgree"></span>
                </div>
            </div>
          </div>
          <div class="layui-col-sm4"> 
                <div class="layui-form-item  layui-form-item--require">
                        <label class="layui-form-label">回复实应付金额(元)</label>
                        <div class="layui-input-block">
                                <input type="text" name="realNeedPay" class="layui-input" maxlength="12" hc-verify="range|decimals2" hc-verify_field="回复实应付金额(元)" hc-verify_min="0" hc-verify_max="999999999.99" placeholder="0~999999999.99">
                        </div>
                    </div>
          </div>
      </div>
      <div class="layui-row">
          <div class="layui-col-sm6">      
                <div class="layui-form-item">        
                    <label class="layui-form-label">对方备注</label>
                    <div class="layui-input-block">
                        <div class="layui-col-sm12">
                            <textarea id="otherRemark" name="otherRemark" class="layui-textarea" disabled style="min-height:50px;cursor:not-allowed" ></textarea>
                        </div>
                    </div>
                </div>
          </div>
          <div class="layui-col-sm6">
                <div class="layui-form-item"> 
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <div class="layui-col-sm12">
                        <textarea id="iRemark" name="iRemark"  placeholder="" class="layui-textarea" style="min-height:50px;"></textarea>
                        </div>
                    </div>
                </div>
          </div>
      </div>
      <div class="layui-form-item  button-bar" style="text-align:center;">
        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit">提交</button>
        <button class="layui-btn layui-btn-primary btn-cancel" type="button">返回</button>
      </div>
      <hr>
      <div class="layui-row">
        <div style="margin-left:90px">
            <div class="layui-col-sm9">
                <div class="layui-form-item"> 
                注：确认应收金额与客户/车主等确认，需要客户/车主支付给自己钱，包括已收金额确认应收金额与对方提交应付金额不一致时，请与客户/车主提前沟通确认。
                </div>
            </div>
        </div>
        </div>
      <div class="layui-row" >
          <div class="layui-col-sm6" style="height:40px">
              <div class="layui-form-item"> 
                <label class="layui-form-label">沟通历史</label>
                <div class="layui-input-block">
                    <div class="layui-col-sm9 pointer">
                        <span href="#" class="communication" >沟通历史链接</span>
                    </div>
                </div>
            </div>
      </div>
      <div class="layui-row">
          <div class="layui-col-sm6"  style="height:40px">
              <div class="layui-form-item"> 
                <label class="layui-form-label">对方提交账单</label>
                <div class="layui-input-block">
                    <div class="layui-col-sm9 pointer">
                        <span id="otherLink" name="otherLink">账单明细链接</span>
                    </div>
                </div>
            </div>
      </div>
      <div class="layui-row">
          <div class="layui-col-sm6" style="height:40px">
              <div class="layui-form-item"> 
                <label class="layui-form-label">回复账单</label>
                <div class="layui-input-block">
                    <div class="layui-col-sm9 pointer">
                        <span id="replyLink" name="replyLink">账单明细链接</span>
                    </div>
                </div>
            </div>
      </div>
    </form>
  </body>
  <script charset="utf-8" src="/view/frame/layui/layui.js"></script>
  <script charset="utf-8" src="/view/frame/static/js/jquery.min.js?v=1.0"></script>
  <script charset="utf-8" src="/view/frame/static/js/layui.district.js?v=1.0"></script>
  <script charset="utf-8" src="/view/tms/static/js/tms_tab.js?v=1.0"></script>
  <script charset="utf-8" src="/view/tms/static/js/tms_index.js?v=1219"></script>
  <script charset="utf-8" src="/view/frame/static/js/lang_zh_CN.js?v=1.0"></script>
  
  <script charset="utf-8" src="/view/frame/static/js/errorCodeMap.js"></script>
  <script charset="utf-8" src="/view/frame/static/js/HC.js?v=1.4"></script>
  <script charset="utf-8" src="/view/tms/static/js/validator.js"></script>
  <script charset="utf-8" src="/view/tms/static/js/bizUtil.js"></script>
  
  <script>
  layui.use(['form', 'layer', 'table', 'laydate'], function(){
    var form = layui.form,
        layer = layui.layer,
        table = layui.table,
        laydate = layui.laydate,
        tmsTab = layui.tms_tab,
        $ = layui.jquery;

    laydate.render({
      elem: '#getMoneyDate' //收款日期
    });

    var $id = $.trim(getUrlParam('customerId'));
    var $billNo;

    roleStatu($id);
    var billMonth,
        $myOrderCount,
        $otherOrderCount,
        $myArkCount,
        $otherArkCount,
        $myTransportCost,
        $otherTransportCost,
        $myExtraCost,
        $otherExtraCost,
        $myTotalCost,
        $status,
        $otherTotalCost;

    //渲染页面
      function roleStatu($id){
        // var $saveData = {
        //   id: $id,
        // }
        // console.log(JSON.stringify($saveData));
        $.ajax({
          type:'GET', 
          url:'/ucenter/general/finance/receivedBills/queryverifyBills.shtml?id='+$id, 
          // dataType:"json",
          // contentType: "application/json",
          // data:JSON.stringify($saveData),
          success:function(d){
            // console.log(d);
            var $code = d.code,
                $msg = d.msg,
                $objects = d.objects;
            if($code === 'SUCCESS'){
                billMonth = $objects.billMonth == null ? "" : $objects.billMonth ;
                $billNo = $objects.receivedBillsNo;
                $myOrderCount = $objects.myOrderCount;
                $otherOrderCount = $objects.otherOrderCount;
                $myArkCount = $objects.myArkCount;
                $otherArkCount = $objects.otherArkCount;
                $myTransportCost = $objects.myTransportCost;
                $otherTransportCost = $objects.otherTransportCost;
                $myExtraCost = $objects.myExtraCost;
                $otherExtraCost = $objects.otherExtraCost;
                $myTotalCost = $objects.myTotalCost;
                $otherTotalCost = $objects.otherTotalCost;
                $status = $objects.status;
                console.log(billMonth);
                $('span[name="receivedBillsNo"]').html($objects.receivedBillsNo);
                $('span[name="customerName"]').html($objects.customerName);
                $('span[name="billMonth"]').html(billMonth == "" ? "" : new Date($objects.billMonth).format('yyyy-MM') );
                $('span[name="orderCount"]').html(($objects.myOrderCount === null ? '':  $objects.myOrderCount) + ($objects.otherOrderCount === null ? '' : '/' + $objects.otherOrderCount));
                $('span[name="arkCount"]').html(($objects.myArkCount === null ? '':  $objects.myArkCount) +  ($objects.otherArkCount === null ? '' : '/' + $objects.otherArkCount));
                $('span[name="transportCost"]').html(($objects.myTransportCost === null ? '':  $objects.myTransportCost) + ($objects.otherTransportCost === null ? '': '/' +  $objects.otherTransportCost));
                $('span[name="extraCost"]').html(($objects.myExtraCost === null ? '':  $objects.myExtraCost) +  ($objects.otherExtraCost === null ? '': '/' + $objects.otherExtraCost));
                $('span[name="totalCost"]').html(($objects.myTotalCost === null ? '':  $objects.myTotalCost) + ($objects.otherTotalCost === null ? '': '/' +  $objects.otherTotalCost));
                $('span[name="badJobsNo"]').html($objects.badJobsNo); // 差异运单号
                $('span[name="badWayTransportCost"]').html($objects.badWayTransportCost);
                $('span[name="badWayExtraCost"]').html($objects.badWayExtraCost);
                $('span[name="badWaySum"]').html($objects.badWaySum);
                $('span[name="receiveCost"]').html($objects.receiveCost);
                $('span[name="handleCost"]').html($objects.handleCost);
                var isAgree = "";
                if($objects.isAgree == true){
                    isAgree = "同意"
                }else if($objects.isAgree == false){
                    isAgree = "不同意"
                }
                $('span[name="isAgree"]').html(isAgree);
                $('textarea[name="otherRemark"]').html($objects.otherRemark);
                // $('span[name="needPay"]').html($objects.needPay);
                // $('textarea[name="iRemark"]').html($objects.iRemark);
            }else{
              parent.layer.alert('操作失败！');
            }
          }
        });
      }
      //差异运单号链接
      $('span[name="badJobsNo"]').on("click",function(){
        var badJobsNo = ($('span[name="badJobsNo"]').html()).split(",");
        var $receivedBillsNo = $('span[name="receivedBillsNo"]').html();
        var $badJobsNo = [];
        console.log(badJobsNo.length); 
        for(var $i = 0 ; $i < badJobsNo.length - 1; $i++ ){
          $badJobsNo.push(badJobsNo[$i])
          // $data.push(data[$i].id);
        }
        console.log($badJobsNo, $receivedBillsNo);
        parent.layer.open({
              type: 2,
              title: '差异详情',
              shadeClose: true,
              shade: 0.8,
              area: ['90%', '80%'],
              content: 'difference.html?badJobsNo=' + $badJobsNo + '&receivedBillsNo=' + $receivedBillsNo
            });
      })

      //对方提交账单链接
       $('span[name="otherLink"]').on("click",function(){
        var $receivedBillsNo = $('span[name="receivedBillsNo"]').html();
        console.log(receivedBillsNo);
        parent.layer.open({
              type: 2,
              title: '对方提交账单',
              shadeClose: true,
              shade: 0.8,
              area: ['90%', '80%'],
              content: 'otherLink.html?receivedBillsNo=' + $receivedBillsNo
            });
      })

      //回复账单链接
       $('span[name="replyLink"]').on("click",function(){
        var $receivedBillsNo = $('span[name="receivedBillsNo"]').html();
        console.log(receivedBillsNo);
        parent.layer.open({
              type: 2,
              title: '回复账单',
              shadeClose: true,
              shade: 0.8,
              area: ['90%', '80%'],
              content: 'replyLink.html?receivedBillsNo=' + $receivedBillsNo
            });
      })

     //监听提交
  form.on('submit(submit)', function(data){
    var $receivedBillsNo = $.trim($('span[name="receivedBillsNo"]').html()),
        $customerName = $.trim($('span[name="customerName"]').html()),
        $billMonth = billMonth,
        $badWayTransportCost = $.trim($('span[name="badWayTransportCost"]').html()),
        $badWayExtraCost = $.trim($('span[name="badWayExtraCost"]').html()),
        $badWaySum = $.trim($('span[name="badWaySum"]').html()),
        $receiveCost = $.trim($('span[name="receiveCost"]').html()),
        $handleCost = $.trim($('span[name="handleCost"]').html()),
        // $isAgree = $.trim($('span[name="isAgree"]').html()),
        $otherRemark = $.trim($('span[name="otherRemark"]').html()),
        $needPay = $.trim($('span[name="needPay"]').html()),
        $realNeedPay = $.trim(data.field.realNeedPay),
        $isDissent = $.trim(data.field.isDissent),
        $iRemark = $.trim(data.field.iRemark);
        // console.log($.trim(data.field.isDissent));
        var $isAgree = "";
        if($('span[name="isAgree"]').html() == "同意"){
            $isAgree = true
        }else if($('span[name="isAgree"]').html() == "不同意"){
            $isAgree = false
        };
        console.log($handleCost);
        console.log($realNeedPay);
        if($handleCost === $realNeedPay){
          $isDissent = true
        }else{
          $isDissent = false
        }
    var $saveData = {
          receivedBillsNo:$receivedBillsNo,
          customerName:$customerName,
          billMonth:$billMonth,
          badWayTransportCost:$badWayTransportCost,
          badWayExtraCost:$badWayExtraCost,
          badWaySum:$badWaySum,
          receiveCost:$receiveCost,
          handleCost:$handleCost,
          isAgree:$isAgree,
          isDissent:$isDissent,
          otherRemark:$otherRemark,
          needPay:$needPay,
          realNeedPay: $realNeedPay,
          iRemark:$iRemark,
          myOrderCount:$myOrderCount,
          otherOrderCount:$otherOrderCount,
          myArkCount:$myArkCount,
          otherArkCount:$otherArkCount,
          myTransportCost:$myTransportCost,
          otherTransportCost:$otherTransportCost,
          myExtraCost:$myExtraCost,
          otherExtraCost:$otherExtraCost,
          myTotalCost:$myTotalCost,
          otherTotalCost:$otherTotalCost,
          status:$status,
    }
    roleStatus($saveData);
    return false;
    });

    function roleStatus($ids){
      console.log($ids);
      var $saveData = $ids;
       $.ajax({
        type:'POST', 
        url:'/ucenter/general/finance/receivedBills/insertVerifyBills.shtml', 
        dataType:"json",      
        contentType:"application/json",               
        data:JSON.stringify($saveData),
        success:function(d){
          var $code = d.code,
              $msg = d.msg,
              $objects = d.objects;
          if($code === 'SUCCESS'){
            // layer.msg('大部分参数都是可以公用的<br>合理搭配，展示不一样的风格', {
            //   btn: ['确定'],
            //   yes:function(){
            //     tmsTab.del($(window.parent.document).find('.layui-tab-title li.layui-this').attr('lay-id'));
            //   }
            // });
            parent.layer.msg('操作成功！');
          }else{
            parent.layer.alert('操作失败！');
          }
        }
      });
  }

    $(".btn-cancel").on("click",function(){
      tmsTab.del($(window.parent.document).find('.layui-tab-title li.layui-this').attr('lay-id'));
    });

    // //差异详情
    // $(".difference").click(function(){
    //   parent.layer.open({
    //     type: 2,
    //     title: '差异详情',
    //     shadeClose: true,
    //     shade: 0.8,
    //     area: ['90%', '80%'],
    //     content: 'difference.html'
    //   });
    // });

    // //账单明细
    // $(".billDetail").click(function(){
    //   parent.layer.open({
    //     type: 2,
    //     title: '应收明细',
    //     shadeClose: true,
    //     shade: 0.8,
    //     area: ['90%', '80%'],
    //     content: 'detailData.html'
    //   });
    // });

    //沟通历史
    $(".communication").click(function(){
      parent.layer.open({
        type: 2,
        title: '沟通历史',
        shadeClose: true,
        shade: 0.8,
        area: ['1100px', '700px'],
        content: 'communication.html?id='+ $id + '&billNo=' + $billNo
      });
    });
  });
  </script>
</html>